package com.ruoyi.chat.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.chat.domain.GameFileEntity;
import com.ruoyi.chat.dto.ChatDtoReq;
import com.ruoyi.chat.dto.GameResp;
import com.ruoyi.chat.mapper.GameFileMapper;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class GameService {

    @Resource
    GameFileMapper fileMapper;
    public List<GameResp> getGames(ChatDtoReq req) {
        log.info("游戏服务开始处理");
        log.info("req:{}",req);
        QueryWrapper<GameFileEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name",req.getMessage());
        List<GameFileEntity> games = fileMapper.selectList(queryWrapper);
        List<GameResp> resp=  new ArrayList<>();
        games.forEach(gameFileEntity -> {
            GameResp gameResp = new GameResp();
            BeanUtils.copyProperties(gameFileEntity,gameResp);
            gameResp.setPublicUrl(gameFileEntity.getDomainPrefix()+ StrUtil.nullToEmpty(gameFileEntity.getRelativePath()));
            gameResp.setLanUrl(gameFileEntity.getLocalPrefix()+StrUtil.nullToEmpty(gameFileEntity.getRelativePath()));
            resp.add(gameResp);
        });
        return resp;
    }
}
